using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

using Acms.SqlDal;

namespace Acms.Bll
{
    public class UserPostVoteTotal : BaseItem
    {
        protected UserPostVoteTotal() : base() { }
        protected UserPostVoteTotal(Hashtable table) : base(table) { }
        protected UserPostVoteTotal(Hashtable table, List<UserPostVoteTotal> collection) : base(table, collection) { }

        public static UserPostVoteTotal CreateInstance()
        {
            return new UserPostVoteTotal();
        }

        private static UserPostVoteTotal Get(Hashtable table)
        {
            if (table != null)
            {
                return new UserPostVoteTotal(table);
            }
            else
            {
                return null;
            }
        }

        private static List<UserPostVoteTotal> Get(Hashtable[] tables)
        {
            if (tables != null)
            {
                List<UserPostVoteTotal> tmp = new List<UserPostVoteTotal>();
                foreach (Hashtable table in tables)
                {
                    tmp.Add(new UserPostVoteTotal(table, tmp));
                }
                return tmp;
            }
            else
            {
                return null;
            }
        }

        public static List<UserPostVoteTotal> GetAllByPostGuid(Guid postGuid)
        {
            UserPostVoteTotalDal dal = new UserPostVoteTotalDal();
            return Get(dal.GetAllByPostGuid(postGuid));
        }

        protected override void Load(Hashtable table)
        {
            postGuid = (Guid)table[UserPostVoteTotalDal.Fields.PostGuid];
            score = (decimal)table[UserPostVoteTotalDal.Fields.Score];
            total = (int)table[UserPostVoteTotalDal.Fields.Total];
        }

        private Guid postGuid;
        public Guid PostGuid
	    {
	        get { return postGuid;}
	    }

        private decimal score;
        public decimal Score
        {
            get { return score; }
        }

        private int total;
        public int Total
        {
            get { return total; }
        }
	
	

        protected override Acms.SqlDal.Base CreateDal()
        {
            return new UserPostVoteTotalDal();
        }

        public static void Sort(List<UserPostVoteTotal> votes, string expression)
        {
            BaseItem.SortList(votes, expression, new UserPostVoteTotalComparer());
        }
    }

    public class UserPostVoteTotalComparer : BaseComparison<UserPostVoteTotal>
    {
        public override int Compare(UserPostVoteTotal x, UserPostVoteTotal y)
        {
            switch (Field.ToLower())
            {
                case "score":
                    return GetReturnValue(x.Score, y.Score);
                case "total":
                    return GetReturnValue(x.Total, y.Total);
            }
            return 0;
        }

    }
}
